import axios from "axios"
const state={
    goodsTypeList: [],
    goodsList:[]
}
const mutations={
    CHANGE_GOODS_TYPE_LIST(state,goodsTypeList){
        state.goodsTypeList=goodsTypeList
    },
    CHANGE_GOODS_LIST(state,goodsList){
        state.goodsList=goodsList
    },
}

const actions={
    addGoodsTypeList({dispatch},params){
       return axios.post("/goodsTypeList",params)

    },
    getGoodsTypeList({commit},params){
        axios.get("/goodsTypeList",{
            params
        }).then(data=>{
            commit("CHANGE_GOODS_TYPE_LIST",data.goodsTypeList)
        })
    },
    getGoodsList({commit},params){
        axios.get("/goodsList",{
            params
        }).then(data=>{
            commit("CHANGE_GOODS_LIST",data.goodsList)
        })
    },
    deleteGoodsType({dispatch},id){
        axios.delete("/goodsTypeList/"+id,{
            params:{
                id
            }
        })
            .then(data=>{
                if(data.ok===1)dispatch("getGoodsTypeList")
            })

    },
    deleteGoods({dispatch},id){
        axios.delete("/goodsList/"+id,{
            params:{
                id
            }
        })
            .then(data=>{
                if(data.ok===1)dispatch("getGoodsList")
            })

    },
}



export default {
    state,
    mutations,
    actions
}